<ui:composition template="/template.xhtml" xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jstl/core"
                xmlns:t="http://myfaces.apache.org/tomahawk">
    <ui:define name="customs">
        <script type="text/javascript" src="#{contextPath}/js/autocomplete.js" language="javascript"/>
        <script type="text/javascript" src="#{contextPath}/counting/counting.js"  language="javascript"/> 
    </ui:define>
    <ui:define name="title">#{resource['countingFast.edition']}</ui:define>
    <ui:define name="main-content">
        <h:form id="docForm">
            <center><h:messages id="errorMessages" styleClass="messages" layout="table"/></center>
            <hr/>            
            <table id="parameters" width="90%" align="center" >
                <tr>
                    <td width="70%">
                        <table id="tabParameters" align="left" width="100%">
                            <tr align="left">
                                <td>Municipio: </td>
                                <td>
                                    <h:selectOneMenu id="townsCombo" value="#{documentRapidBean.town}" class="SelectOption"
                                                     onchange="this.form.submit();" valueChangeListener="#{documentRapidBean.processTownChange}">
                                        <t:selectItems id="townOption" value="#{documentRapidBean.towns}" var="town" itemLabel="#{town.name}" itemValue="#{town}"/>
                                        <f:converter converterId="objconverter"/>
                                    </h:selectOneMenu>
                                    <br/>
                                    <h:outputText id="townName" value=""/>
                                </td>
                            </tr>
                            <tr align="left">
                                <td>Centro: </td>
                                <td>
                                    <h:selectOneMenu id="ballotsCombo" value="#{documentRapidBean.ballotCentre}" class="SelectOption">
                                        <t:selectItems id="ballotOption" value="#{documentRapidBean.ballots}" var="ballotCentre" itemLabel="#{ballotCentre.description}" itemValue="#{ballotCentre}"/>
                                        <f:converter converterId="objconverter"/>
                                    </h:selectOneMenu>
                                    <br/>
                                    <h:outputText id="ballotDesc" value=""/>
                                </td>
                            </tr>
                            <tr align="left">
                                <td>Jrv: </td>
                                <td>
                                    <input type="text" id="autocomplete_jrv" name="autocomplete_jrv" />
                                </td>
                            </tr>
                            <div id="autocomplete_choices" class="autocomplete"></div> 
                        </table>
                    </td>
                    <td width="30%">
                        <table id="tabCalculations" align="left" width="100%">
                            <thead>
                                <tr align="center"><th>Suma de Votos</th><th></th></tr>
                            </thead>
                            <tr>
                                <td align="left">Depositados Calculados</td>
                                <td><h:outputText id="calcDepositedVotes" size="8" value="#{documentRapidBean.document.calcDepositedVotes}"/></td>
                            </tr>
                            <tr>
                                <td align="left">#{resource['counting.validCalc']}</td>
                                <td><h:outputText id="calcValidVotes" size="8" value="#{documentRapidBean.document.validVotes}"/></td>
                            </tr>
                            <tr>
                                <td align="left">Muestra</td>
                                <td><h:selectBooleanCheckbox disabled="true" title="Muestra" value="#{documentRapidBean.document.jrv.sample}"/></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>

            <br/>
            <table width="70%" align="center">
                <tr align="center">
                    <th>PLC</th>
                    <th>FSLN</th>
                    <th>PC</th>
                    <th>YATAMA</th>
                    <th>ALN</th>
                    <th>APRE</th>
                    <th>APLI</th>
                </tr>
                <tr>
                    <td align="center">1</td>
                    <td align="center">2</td>
                    <td align="center">4</td>
                    <td align="center">8</td>
                    <td align="center">9</td>
                    <td align="center">10</td>
                    <td align="center">13</td>
                </tr>
                <tr>
                    <td align="center"><img src="#{contextPath}/images/BANDERA_PLC.jpg" width="75" height="40"/></td>
                    <td align="center"><img src="#{contextPath}/images/BANDERA_FSLN.jpg" width="75" height="40"/></td>
                    <td align="center"><img src="#{contextPath}/images/BANDERA_PC.jpg" width="75" height="40"/></td>
                    <td align="center"><img src="#{contextPath}/images/BANDERA_YATAMA.jpg" width="75" height="40"/></td>
                    <td align="center"><img src="#{contextPath}/images/BANDERA_ALN.jpg" width="75" height="40"/></td>
                    <td align="center"><img src="#{contextPath}/images/BANDERA_APRE.jpg" width="75" height="40"/></td>
                    <td align="center"><img src="#{contextPath}/images/BANDERA_APLI.jpg" width="75" height="40"/></td>
                </tr>
                <tr>
                    <td align="center"><h:inputText id="votePlc" size="12" value="#{documentRapidBean.votePlc}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                    <td align="center"><h:inputText id="voteFsln" size="12" value="#{documentRapidBean.voteFsln}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                    <td align="center"><h:inputText id="votePc" size="12" value="#{documentRapidBean.votePc}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                    <td align="center"><h:inputText id="voteYatama" size="12" value="#{documentRapidBean.voteYatama}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                    <td align="center"><h:inputText id="voteAln" size="12" value="#{documentRapidBean.voteAln}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                    <td align="center"><h:inputText id="votePrn" size="12" value="#{documentRapidBean.votePrn}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>                            
                    <td align="center"><h:inputText id="votePli" size="12" value="#{documentRapidBean.votePli}" onkeypress="return validateNumber(event);" onblur="calc();"/></td>
                </tr>
            </table>
            <br/>
            <table width="80" align="center">
                <tr width="50%" align="center">
                    <th>#{resource['counting.deposited']}</th>
                    <th>#{resource['counting.valid']}</th>
                    <th>#{resource['counting.nulls']}</th>
                </tr>
                <tr width="50%">
                    <td><h:inputText id="depositedVotes" value="#{documentRapidBean.document.depositedVotes}" onchange="return calcNulls();"/></td>
                    <td><h:inputText id="validVotes" value="#{documentRapidBean.document.validVotes}" onchange="return calcNulls();"/></td>
                    <td><h:inputText id="nullVotes" value="#{documentRapidBean.document.nullVotes}" onchange="return calcNullSingle();"/></td>
                </tr>
            </table>
            <br/>
            <table width="50" align="center">
                <tr>
                    <td align="left">Impugnada</td>
                    <td><h:selectBooleanCheckbox title="Impugnada" value="#{documentRapidBean.document.impugnada}"/></td>
                </tr>
                <tr>
                    <td align="left">Sin Acta</td>
                    <td><h:selectBooleanCheckbox title="Sin Acta" value="#{documentRapidBean.document.withoutDoc}"/></td>
                </tr>
            </table>
            <br/>
            <h:inputHidden id="operation" value="INGRESO"/>
            <h:inputHidden id="counting" value="#{documentRapidBean.counting}"/>
            <h:inputHidden id="jrvHidden" value="#{documentRapidBean.jrv}">
                <f:converter converterId="objconverter"/>
            </h:inputHidden>
            <h:inputHidden id="ballotHidden" value="#{documentRapidBean.ballotCentre}">
                <f:converter converterId="objconverter"/>
            </h:inputHidden>
            <table align="center">
                <td><h:commandButton title="Guardar" action="#{documentRapidBean.save}"  image="/images/Save.png" onclick="return validations();"/></td>
                <td><h:commandButton title="Reiniciar" action="#{documentRapidBean.reset}"  image="/images/Redo.png"/></td>
            </table>
        </h:form>
        <script language="javascript">
            cleanup();
        </script>
    </ui:define>
    <ui:define name="news-content">
        <span class="smalltitle">Registro</span><br/><br />

        <span class="smallredtext">Total Registrados</span><br />
        <span class="bodytext">
            <c:if test="#{currentUser != null}">
                #{documentRapidBean.totalInserted} JRVs
            </c:if>
        </span><br/><br/>
        <span class="smallredtext">Último Insertado</span><br />
        <span class="bodytext">
            <c:if test="#{currentUser != null}">
                Jrv: #{documentRapidBean.lastInsertedDocument.jrv.code}
                <br/>
                Votos: #{documentRapidBean.lastInsertedDocument.calcDepositedVotes}
            </c:if>
        </span><br/>
    </ui:define>
</ui:composition>